<?php

namespace app\common;

use app\common\model\Notification as ModelNotification;
use Exception;
use think\facade\Log;

class Notification
{
    protected static $link;
    /**
     * @param int $user_id
     * @param int $type 消息类型 1 普通文字  2文章(评论) 3指定页面
     * @param int $target_id 目标ID(页面Url)
     *  */
    public static function send($uid, $content, $type = 1, $target_id = null, $ext = null)
    {
        try {
            $data = [
                'user_id' => $uid,
                'target_id' => $target_id,
                'type' => $type,
                'content' => $content,
                'ext' => $ext
            ];
            $res = ModelNotification::create($data);
            return $res;
        } catch (Exception $e) {
            Log::error('通知发送失败：' . $e->getMessage());
        }
    }
}
